/*
 * Customs rules and methods for the jQuery validation plugin
 * Author : RichCongress
 */
/*
/*
 * 
 */
jQuery.validator.addMethod("check_extensions", function(value, element){
	var extArray = new Array(".gif", ".jpg", ".png", ".jpeg");
	var allowSubmit = false;
	if (value != "") {
		while (value.indexOf("\\") != -1) 
			value = value.slice(value.indexOf("\\") + 1);
			ext = value.slice(value.indexOf(".")).toLowerCase();
			for (var i = 0; i < extArray.length; i++) {
				if (extArray[i] == ext) { allowSubmit = true; break; }
			}
		if (!allowSubmit) {
			//alert("Utilisez les suivantes extensions:  " +
			//(extArray.join("  ")) + ".\nMerci"); 
			 return false;
		 }
	 }
	return true;
	
});
jQuery.validator.addMethod("fax", function(value, element){
	if (value != "") {
		//var expr = /(\d{2}[ \.]{0,1}){7}/;
		var expr = /0[0-9]([ .-]?[0-9]{2}){4}/;
		if (!value.match(expr))
			return false;
	 }
	return true;
	
});
jQuery.validator.addMethod("telephone", function(value, element){
	if (value != "") {
		//var expr = /(\d{2}[ \.]{0,1}){7}/;
		var expr = /0[0-9]([ .-]?[0-9]{2}){4}/;
		if (!value.match(expr))
			return false;
	 }
	return true;
	
});
jQuery.validator.addMethod("check_liste", function(value, element){
	if (value == -1)
		return false;
	return true;
	
	
});


jQuery.validator.addClassRules({
	postcode : {
		minlength : 5,
		maxlength : 5,
		digits : true
	},
	
	address : {
		minlength : 5
	},
	
	city : {
		minlength : 3
	},
	
	tel : {
		check_tel : true
	},
	
	fax : {
		check_fax : true
	},
	
	liste : {
		check_liste : true
	},
	
	unregistred_mail:{
		email:true
	},
	extension_allowed:{
		check_extensions:true
	},
	password:{
		minlength: 6
	},
	password_confirm:{
		equalTo: "#password"
	}/*,
	siret_number: {
		minlength: 15,
		maxlength: 15,
		digits: true
	}
	*/
});
